package com.quasar.hpatient.dialog;

import android.app.Activity;
import android.widget.TextView;

import com.quasar.hpatient.R;

import java.util.Arrays;
import java.util.List;

import lib.quasar.base.dialog.BaseDialog;
import lib.quasar.widget.wheel.WheelView;

/**
 * description: 定性
 * created by kalu on 2018/5/10 11:11
 */
public class QualitativeDialog extends BaseDialog {

    private final List<String> mData1 = Arrays.asList(
            "(阴性)--1", "(阳性)微量或者+-", "(阳性)1+或者+", "(阳性)2+或者++", "(阳性)3+或者+++", "(阳性)4+或者++++"
    );
    private final List<String> mData2 = Arrays.asList(
            "-1", "0.5", "1", "2", "3", "4"
    );
    /****************************************/

    private OnDialogChangeListener listener;

    public QualitativeDialog(Activity activity) {
        super(activity);
    }

    @Override
    protected int initView() {
        return R.layout.layout_dialog_qualitative;
    }

    @Override
    protected void initData() {

        findViewById(R.id.dialog_qualitative_back).setOnClickListener(v -> dismiss());
        findViewById(R.id.dialog_qualitative_ok).setOnClickListener(v -> cancel());

        WheelView wheel = findViewById(R.id.dialog_qualitative_wheel);
        wheel.setLoop(false);
        wheel.setList(mData1);
    }

    @Override
    public void cancel() {

        if (null != listener) {
            WheelView wheel = findViewById(R.id.dialog_qualitative_wheel);
            if (null != wheel) {
                final int index = wheel.getSelectPosition();
                listener.onChange(mData2.get(index));
            }
        }

        super.cancel();
    }

    public void setTitle(String title) {
        TextView text = findViewById(R.id.dialog_qualitative_title);
        if (null == text) return;
        text.setText(title);
    }

    public void setOnDialogChangeListener(OnDialogChangeListener mListener) {
        this.listener = mListener;
    }

    public interface OnDialogChangeListener {
        void onChange(String input);
    }
}
